package com.mobiporter.adias.tags.utils;

import java.util.HashMap;
import java.util.Map;

public class TagBuilder 
{
	private String tagName ;
	private HashMap<String, String> attributes ; 
	private String innerHTML ; 
	
	public String getTagName() {
		return tagName;
	}

	public void setTagName(String tagName) {
		this.tagName = tagName;
	}

	public HashMap<String, String> getAttributes() {
		return attributes;
	}

	public void setAttributes(HashMap<String, String> attributes) {
		this.attributes = attributes;
	}

	public String getInnerHTML() {
		return innerHTML;
	}

	public void setInnerHTML(String innerHTML) {
		this.innerHTML = innerHTML;
	}

	private TagBuilder()
	{
		
	}
	
	public static TagBuilder newInstance(String tagName)
	{
		TagBuilder t = new TagBuilder() ;
		t.tagName = tagName ;
		t.attributes = new HashMap<String, String>() ;
		return t ;
	}
	
	public void addAttribute(String name, String value )
	{
		getAttributes().put(name, value); 
	}
	
	public String toString()
	{
		String html = "<" + getTagName() ;
		for (Map.Entry<String, String> entry : getAttributes().entrySet())
		{
			html += " " + entry.getKey() + "=\""+ entry.getValue()+"\"" ;
		}
		if (innerHTML!=null)
		{
			html += ">"+getInnerHTML()+"</"+getTagName()+">" ;
		}
		else
			html +="/>" ;
		return html ;
	}
}
